|
Download
FAQ History |
|
API
Search Feedback |
The Example JSP Pages
This chapter illustrates JSTL with excerpts from the JSP version of the Duke's Bookstore application discussed in Chapter 12 rewritten to replace the JavaBeans component database helper object with direct calls to the database via the JSTL SQL tags. For most applications, it is better to encapsulate calls to a database in a bean. JSTL includes SQL tags for situations where a new application is being prototyped and the overhead of creating a bean may not be warranted.
The source for the Duke's Bookstore application is located in the
<INSTALL>/j2eetutorial14/examples/web/bookstore4/directory created when you unzip the tutorial bundle (see About the Examples). A samplebookstore4.waris provided in<INSTALL>/j2eetutorial14/examples/web/provided-wars/. To build, package, deploy, and run the example:
- Build and package the bookstore common files as described in Duke's Bookstore Examples.
- In a terminal window, go to
<INSTALL>/j2eetutorial14/examples/web/bookstore4/.- Run
asantbuild. This target will spawn any necessary compilations and copy files to the<INSTALL>/j2eetutorial14/examples/web/bookstore4/build/directory.- Start the J2EE application server.
- Perform all the operations described in Accessing Databases from Web Applications.
- Start
deploytool.- Create a Web application called
bookstore4by running the New Web Application Wizard. Select FileNew
Web Application WAR.
- New Web Application Wizard
- Select the Create New Stand-Alone WAR Module radio button.
- Click Browse and in the file chooser, navigate to
<INSTALL>/j2eetutorial14/examples/web/bookstore4/.- In the File Name field, enter
bookstore4.- Click Choose Module File.
- In the WAR Display Name field, enter
bookstore4.- In the Context Root field, enter
/bookstore4.- Click Edit to add the content files.
- In the Edit Contents dialog, navigate to
<INSTALL>/j2eetutorial14/examples/web/bookstore4/build/. Select the JSP pagesbookstore.jsp,bookdetails.jsp,bookcatalog.jsp,bookshowcart.jsp,bookcashier.jsp,bookreceipt.jspand thedatabaseandtemplatedirectories and click Add. Click OK.- Add the shared bookstore library. Navigate to
<INSTALL>/j2eetutorial14/examples/build/web/bookstore/dist/. Selectbookstore.jarand Click Add.- Click OK.
- Click Next.
- Select the JSP radio button.
- Click Next.
- Select
bookstore.jspfrom the JSP Filename combo box.- Click Finish.
- Add each of the Web components listed in Table 13-1. For each component:
- Select File
New
Web Application WAR.
- Click the Add to Existing WAR Module radio button Since the WAR contains all of the JSP pages, you do not have to add any more content.
- Click Next.
- Select the JSP radio button and the Component Aliases checkbox.
- Click Next.
- Select the page from the JSP Filename combo box.
- Click Next.
- Click Add. Enter the alias.
- Click Finish.
- Add the JSTL resource bundle basename context parameter.
- Set prelude and codas for all JSP pages.
- Select the JSP Properties tab.
- Click the Add button next to the Name list.
- Enter
bookstore4.- Click the Add button next to the URL Pattern list.
- Enter
/*.jsp.- Click the Edit button next to the Include Preludes list.
- Click Add.
- Enter
/template/prelude.jspf.- Click OK.
- Click the Edit button next to the Include Codas list.
- Click Add.
- Enter
/template/coda.jspf.- Click OK.
- Add a resource reference for the database.
- Select the Resource Refs tab.
- Click Add.
- Enter
jdbc/BookDBin the Coded Name field.- Accept the default type
javax.sql.DataSource.- Accept the default authorization
Container.- Accept the default selected
Shareable.- Enter
jdbc/BookDBin the JNDI name field of the Deployment setting for jdbc/BookDB frame.- Select File
Save.
- Deploy the application.
- Open the bookstore URL
http://localhost:1024/bookstore4/bookstore.See Troubleshooting for help with diagnosing common problems.
|
Download
FAQ History |
|
API
Search Feedback |
All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.